class MyQueue(object):
    """自定义队列"""

    def __init__(self, size=None):
        self.items = []  # 像python的list，PHP的Array数组，Java的动态数组，go的列表，都可以实现自定义队列
        self.maxsize = size

    def is_empty(self):
        """判断队列是否为空，也就是队列的长度是否为0"""
        return self.items == []

    def size(self):
        """获取队列长度"""
        return len(self.items)

    def enqueue(self, item):
        """进队"""
        if self.size() < self.maxsize or self.maxsize is None:
            self.items.insert(0, item)
        else:
            raise Exception("队列已满！")

    def dequeue(self):
        """出队"""
        if not self.is_empty():
            return self.items.pop()
        else:
            raise Exception("队列为空！")


if __name__ == '__main__':
    q = MyQueue(3)
    q.enqueue("hello")
    q.enqueue("world")
    q.enqueue("python")
    #     q.enqueue("python")
    print(q.size())

    print(q.dequeue())
    print(q.dequeue())
    print(q.dequeue())
    # print(q.dequeue())

    print(q.is_empty())
